#include "SDL.h"   /* All SDL App's need this */
#include <stdio.h>
#include <fstream>
#include "sdlFunctions.h"

int main(int argc, char* argv[]) {

    SDL_Surface *screen;
    /* Initialize the SDL library */
    if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
        fprintf(stderr,
                "Couldn't initialize SDL: %s\n", SDL_GetError());
        exit(1);
    }
    /* Clean up on exit */
    atexit(SDL_Quit);
    /*
     * Initialize the display in a 640x480 8-bit palettized mode,
     * requesting a software surface
     */
 //   screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE);
	screen = SDL_SetVideoMode(1280, 768,16, SDL_SWSURFACE);
    if ( screen == NULL ) {
        fprintf(stderr, "Couldn't set 640x480x8 video mode: %s\n",
                        SDL_GetError());
        exit(1);
    }
	SDL_WM_SetCaption("Hello World",NULL);
	display_bmp("../resource/1.bmp",screen);

	fprintf(stdout,"pixel value is:%i",getpixel(screen,100,100));
	
	/*
	for(int i=0;i<500;i++)
		for(int j=0;j<500;j++){
			putpixel(screen,100,100,4000);
			//fprintf(stdout,"pixel value is:%i",getpixel(screen,100,100));
		}
		*/


	/* Code to set a yellow pixel at the center of the screen */

    int x, y;
    Uint32 yellow;

    /* Map the color yellow to this display (R=0xff, G=0xFF, B=0x00)
       Note:  If the display is palettized, you must set the palette first.
    */
    yellow = SDL_MapRGB(screen->format, 0xff, 0xff, 0x00);

    x = screen->w / 2;
    y = screen->h / 2;

    /* Lock the screen for direct access to the pixels */
    if ( SDL_MUSTLOCK(screen) ) {
        if ( SDL_LockSurface(screen) < 0 ) {
            fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError());
            exit(-1);
        }
    }

    putpixel(screen, x, y, yellow);

    if ( SDL_MUSTLOCK(screen) ) {
        SDL_UnlockSurface(screen);
    }
    /* Update just the part of the display that we've changed */
    SDL_UpdateRect(screen, x, y, 1, 1);

 

	system("pause");
}

